#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <exception>
#include <cstring>

using namespace std;

typedef struct TTerm {
	int type;
	string value;
	vector<TTerm> parts;
} TTerm;

class MyException : public exception {
	public:
		string info;
		string line;
	
		virtual ~MyException(void) throw() {}
};

const int BNFWORD = 0;
const int ADDOP = 1;
const int ASSIGNMENT = 2;
const int DIGIT = 3;
const int DIGITS = 4;
const int EXPRESSION = 5;
const int FACTOR = 6;
const int FACTORS = 7;
const int FACTORS_TAIL = 8;
const int LETTER = 9;
const int LETTERDIGITS = 10;
const int LINE = 11;
const int MULOP = 12;
const int MULTIPLE_LINES = 13;
const int MYFILE = 14;
const int NUMBER = 15;
const int PRINT = 16;
const int RESET = 17;
const int TERM = 18;
const int TERMS = 19;
const int TERMS_TAIL = 20;
const int VAR = 21;

string trim(string s) {
	int begin = s.find_first_not_of(" \t\r\n");
	int end = s.find_last_not_of(" \t\r\n");
	if (begin == -1) return "";
	return s.substr(begin, end+1-begin);
}

TTerm matchBNFWord(const string word, string& line){
	TTerm BNFWord;
	BNFWord.type = BNFWORD;
	
	if (line.length() < word.length()) {
		MyException e;
		e.info = "too short line in BNFWord";
		e.line = line;
		throw e;
	}
	for (unsigned int i=0; i<word.length(); ++i) {
		if (word[i] != line[i]) {
			MyException e;
			e.info = "mismatch in BNFWord";
			e.line = line;
			throw e;
		}
	}
	line = line.substr(word.length(), line.length()-word.length());
	BNFWord.value = word;
	
	return BNFWord;
}

void needSeparator(string& line) {
	if (line.length()>0 && line[0]!=' ') {
		MyException e;
		e.info = "need separator";
		e.line = line;
		throw e;
	}
	line = trim(line);
}

TTerm match_addop(string& line);
TTerm match_assignment(string& line);
TTerm match_digit(string& line);
TTerm match_digits(string& line);
TTerm match_expression(string& line);
TTerm match_factor(string& line);
TTerm match_factors(string& line);
TTerm match_factors_tail(string& line);
TTerm match_letter(string& line);
TTerm match_letterdigits(string& line);
TTerm match_line(string& line);
TTerm match_mulop(string& line);
TTerm match_multiple_lines(string& line);
TTerm match_myfile(string& line);
TTerm match_number(string& line);
TTerm match_print(string& line);
TTerm match_reset(string& line);
TTerm match_term(string& line);
TTerm match_terms(string& line);
TTerm match_terms_tail(string& line);
TTerm match_var(string& line);

TTerm match_myfile(string& line) {
	TTerm _myfile;
	TTerm t;
	_myfile.type = MYFILE;
	
	t = match_multiple_lines(line);
	_myfile.parts.push_back(t);
	
	t = matchBNFWord("#", line);
	_myfile.parts.push_back(t);
	
	return _myfile;
}

TTerm match_multiple_lines(string& line) {
	TTerm _multiple_lines;
	TTerm t;
	_multiple_lines.type = MULTIPLE_LINES;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _multiple_lines.parts;
		try {
			t = match_line(line);
			_multiple_lines.parts.push_back(t);
			
			t = match_multiple_lines(line);
			_multiple_lines.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_multiple_lines.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _multiple_lines.parts;
		try {
			t = match_line(line);
			_multiple_lines.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_multiple_lines.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in MULTIPLE_LINES";
		myE.line = line;
		throw myE;
	}
	return _multiple_lines;
}

TTerm match_line(string& line) {
	TTerm _line;
	TTerm t;
	_line.type = LINE;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _line.parts;
		try {
			hasErr = true;
			bakLn[1] = line;
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _line.parts;
				try {
					t = match_assignment(line);
					_line.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_line.parts = bakParts;
				}
			}
			
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _line.parts;
				try {
					t = match_print(line);
					_line.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_line.parts = bakParts;
				}
			}
			
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _line.parts;
				try {
					t = match_reset(line);
					_line.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_line.parts = bakParts;
				}
			}
			
			if (hasErr) {
				line = bakLn[1];
				myE.info = "mismatch in LINE";
				myE.line = line;
				throw myE;
			}
			t = matchBNFWord(";", line);
			_line.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_line.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _line.parts;
		try {
			t = matchBNFWord(";", line);
			_line.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_line.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in LINE";
		myE.line = line;
		throw myE;
	}
	return _line;
}

TTerm match_assignment(string& line) {
	TTerm _assignment;
	TTerm t;
	_assignment.type = ASSIGNMENT;
	
	t = match_var(line);
	_assignment.parts.push_back(t);
	
	t = matchBNFWord(":=", line);
	_assignment.parts.push_back(t);
	
	t = match_expression(line);
	_assignment.parts.push_back(t);
	
	return _assignment;
}

TTerm match_print(string& line) {
	TTerm _print;
	TTerm t;
	_print.type = PRINT;
	
	t = matchBNFWord("PRINT", line);
	_print.parts.push_back(t);
	
	needSeparator(line);
	
	t = match_var(line);
	_print.parts.push_back(t);
	
	return _print;
}

TTerm match_reset(string& line) {
	TTerm _reset;
	TTerm t;
	_reset.type = RESET;
	
	t = matchBNFWord("RESET", line);
	_reset.parts.push_back(t);
	
	return _reset;
}

TTerm match_expression(string& line) {
	TTerm _expression;
	TTerm t;
	_expression.type = EXPRESSION;
	
	t = match_terms(line);
	_expression.parts.push_back(t);
	
	return _expression;
}

TTerm match_terms(string& line) {
	TTerm _terms;
	TTerm t;
	_terms.type = TERMS;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _terms.parts;
		try {
			t = match_term(line);
			_terms.parts.push_back(t);
			
			t = match_terms_tail(line);
			_terms.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_terms.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _terms.parts;
		try {
			t = match_term(line);
			_terms.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_terms.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in TERMS";
		myE.line = line;
		throw myE;
	}
	return _terms;
}

TTerm match_terms_tail(string& line) {
	TTerm _terms_tail;
	TTerm t;
	_terms_tail.type = TERMS_TAIL;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _terms_tail.parts;
		try {
			t = match_addop(line);
			_terms_tail.parts.push_back(t);
			
			t = match_term(line);
			_terms_tail.parts.push_back(t);
			
			t = match_terms_tail(line);
			_terms_tail.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_terms_tail.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _terms_tail.parts;
		try {
			t = match_addop(line);
			_terms_tail.parts.push_back(t);
			
			t = match_term(line);
			_terms_tail.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_terms_tail.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in TERMS_TAIL";
		myE.line = line;
		throw myE;
	}
	return _terms_tail;
}

TTerm match_term(string& line) {
	TTerm _term;
	TTerm t;
	_term.type = TERM;
	
	t = match_factors(line);
	_term.parts.push_back(t);
	
	return _term;
}

TTerm match_factors(string& line) {
	TTerm _factors;
	TTerm t;
	_factors.type = FACTORS;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factors.parts;
		try {
			t = match_factor(line);
			_factors.parts.push_back(t);
			
			t = match_factors_tail(line);
			_factors.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factors.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factors.parts;
		try {
			t = match_factor(line);
			_factors.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factors.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in FACTORS";
		myE.line = line;
		throw myE;
	}
	return _factors;
}

TTerm match_factors_tail(string& line) {
	TTerm _factors_tail;
	TTerm t;
	_factors_tail.type = FACTORS_TAIL;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factors_tail.parts;
		try {
			t = match_mulop(line);
			_factors_tail.parts.push_back(t);
			
			t = match_factor(line);
			_factors_tail.parts.push_back(t);
			
			t = match_factors_tail(line);
			_factors_tail.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factors_tail.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factors_tail.parts;
		try {
			t = match_mulop(line);
			_factors_tail.parts.push_back(t);
			
			t = match_factor(line);
			_factors_tail.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factors_tail.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in FACTORS_TAIL";
		myE.line = line;
		throw myE;
	}
	return _factors_tail;
}

TTerm match_factor(string& line) {
	TTerm _factor;
	TTerm t;
	_factor.type = FACTOR;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factor.parts;
		try {
			t = matchBNFWord("(", line);
			_factor.parts.push_back(t);
			
			t = match_expression(line);
			_factor.parts.push_back(t);
			
			t = matchBNFWord(")", line);
			_factor.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factor.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factor.parts;
		try {
			t = match_var(line);
			_factor.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factor.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _factor.parts;
		try {
			t = match_number(line);
			_factor.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_factor.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in FACTOR";
		myE.line = line;
		throw myE;
	}
	return _factor;
}

TTerm match_addop(string& line) {
	TTerm _addop;
	TTerm t;
	_addop.type = ADDOP;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _addop.parts;
		try {
			t = matchBNFWord("+", line);
			_addop.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_addop.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _addop.parts;
		try {
			t = matchBNFWord("-", line);
			_addop.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_addop.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in ADDOP";
		myE.line = line;
		throw myE;
	}
	return _addop;
}

TTerm match_mulop(string& line) {
	TTerm _mulop;
	TTerm t;
	_mulop.type = MULOP;
	
	t = matchBNFWord("*", line);
	_mulop.parts.push_back(t);
	
	return _mulop;
}

TTerm match_var(string& line) {
	TTerm _var;
	TTerm t;
	_var.type = VAR;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _var.parts;
		try {
			t = match_letter(line);
			_var.parts.push_back(t);
			
			t = match_letterdigits(line);
			_var.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_var.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _var.parts;
		try {
			t = match_letter(line);
			_var.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_var.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in VAR";
		myE.line = line;
		throw myE;
	}
	return _var;
}

TTerm match_letterdigits(string& line) {
	TTerm _letterdigits;
	TTerm t;
	_letterdigits.type = LETTERDIGITS;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letterdigits.parts;
		try {
			hasErr = true;
			bakLn[1] = line;
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _letterdigits.parts;
				try {
					t = match_letter(line);
					_letterdigits.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_letterdigits.parts = bakParts;
				}
			}
			
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _letterdigits.parts;
				try {
					t = match_digit(line);
					_letterdigits.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_letterdigits.parts = bakParts;
				}
			}
			
			if (hasErr) {
				line = bakLn[1];
				myE.info = "mismatch in LETTERDIGITS";
				myE.line = line;
				throw myE;
			}
			t = match_letterdigits(line);
			_letterdigits.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letterdigits.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letterdigits.parts;
		try {
			hasErr = true;
			bakLn[1] = line;
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _letterdigits.parts;
				try {
					t = match_letter(line);
					_letterdigits.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_letterdigits.parts = bakParts;
				}
			}
			
			if (hasErr) {
				hasErr = false;
				line = bakLn[1];
				bakParts = _letterdigits.parts;
				try {
					t = match_digit(line);
					_letterdigits.parts.push_back(t);
					
				}
				catch(MyException e){
					hasErr = true;
					myE = e;
					_letterdigits.parts = bakParts;
				}
			}
			
			if (hasErr) {
				line = bakLn[1];
				myE.info = "mismatch in LETTERDIGITS";
				myE.line = line;
				throw myE;
			}
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letterdigits.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in LETTERDIGITS";
		myE.line = line;
		throw myE;
	}
	return _letterdigits;
}

TTerm match_number(string& line) {
	TTerm _number;
	TTerm t;
	_number.type = NUMBER;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _number.parts;
		try {
			t = match_digits(line);
			_number.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_number.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _number.parts;
		try {
			t = matchBNFWord("-", line);
			_number.parts.push_back(t);
			
			t = match_digits(line);
			_number.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_number.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in NUMBER";
		myE.line = line;
		throw myE;
	}
	return _number;
}

TTerm match_digits(string& line) {
	TTerm _digits;
	TTerm t;
	_digits.type = DIGITS;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digits.parts;
		try {
			t = match_digit(line);
			_digits.parts.push_back(t);
			
			t = match_digits(line);
			_digits.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digits.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digits.parts;
		try {
			t = match_digit(line);
			_digits.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digits.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in DIGITS";
		myE.line = line;
		throw myE;
	}
	return _digits;
}

TTerm match_letter(string& line) {
	TTerm _letter;
	TTerm t;
	_letter.type = LETTER;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("A", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("B", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("C", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("D", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("E", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("F", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("G", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("H", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("I", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("J", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("K", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("L", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("M", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("N", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("O", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("P", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("Q", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("R", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("S", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("T", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("U", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("V", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("W", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("X", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("Y", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("Z", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("a", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("b", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("c", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("d", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("e", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("f", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("g", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("h", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("i", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("j", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("k", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("l", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("m", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("n", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("o", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("p", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("q", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("r", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("s", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("t", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("u", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("v", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("w", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("x", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("y", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _letter.parts;
		try {
			t = matchBNFWord("z", line);
			_letter.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_letter.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in LETTER";
		myE.line = line;
		throw myE;
	}
	return _letter;
}

TTerm match_digit(string& line) {
	TTerm _digit;
	TTerm t;
	_digit.type = DIGIT;
	
	bool hasErr = false;
	MyException myE;
	string bakLn[10];
	vector<TTerm> bakParts;
	
	hasErr = true;
	bakLn[0] = line;
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("0", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("1", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("2", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("3", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("4", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("5", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("6", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("7", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("8", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		hasErr = false;
		line = bakLn[0];
		bakParts = _digit.parts;
		try {
			t = matchBNFWord("9", line);
			_digit.parts.push_back(t);
			
		}
		catch(MyException e){
			hasErr = true;
			myE = e;
			_digit.parts = bakParts;
		}
	}
	
	if (hasErr) {
		line = bakLn[0];
		myE.info = "mismatch in DIGIT";
		myE.line = line;
		throw myE;
	}
	return _digit;
}

